package com.example.java.controller;

import com.example.java.pojo.ResponseMessage;
import com.example.java.pojo.User;
import com.example.java.pojo.UserAddress;
import com.example.java.pojo.dto.UserAddressDto;
import com.example.java.pojo.dto.UserDto;
import com.example.java.service.IUserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController    //接口方法返回的对象，转换成json文本
@RequestMapping("/useraddress")    // localhost:8080/useraddress/****
public class UserAddressController {

    @Autowired
    IUserAddressService userAddressService;

    //添加一个地址
    @PostMapping("/addaddress")
    public ResponseMessage<UserAddress> addAddress(@Validated @RequestBody UserAddressDto userAddress){
        UserAddress userNewAddress = userAddressService.addAddress(userAddress);//业务中添加一个新地址
        return ResponseMessage.success(userNewAddress);
    }

    //根据地址id删除一个地址
    @DeleteMapping("/{id}")
    public ResponseMessage<UserAddress> deleteUserAddress(@PathVariable Integer id){
        userAddressService.deleteUserAddress(id);//业务中根据id来删除一个用户
        return ResponseMessage.success();
    }
}
